{extend name="public/common"}

{block name="style"}
<title>上级来文详情</title>
<link rel="stylesheet" href="/home/css/documents/detail.css?v={$Think.config.version}">
{/block}

{block name="body"}
<div id="app" v-cloak>
    <div class="header">
        <p class="title">{{detail.title}}</p>
        <p class="publisher">
            <span>{{detail.type_text}}</span>
            <span>{{detail.create_time | timeToString('ymd')}}</span>
        </p>
    </div>
    <div :class="(detail.status == 0 || (detail.status == 1 && detail.is_file == 1))?'body':''">
        <div class="article" v-html="detail.content"></div>
        <div class="box" v-if="(detail.attachment || []).length > 0">
            <p>附件</p>
            <div class="files">
                <div class="file" v-for="i in (detail.attachment || [])" @click="downFile(i.path)">
                    <img src="/home/images/documents/doc.png" v-if="i.ext=='doc'"/>
                    <img src="/home/images/documents/pdf.png" v-else-if="i.ext=='pdf'"/>
                    <img src="/home/images/documents/ppt.png" v-else-if="i.ext=='ppt'"/>
                    <img src="/home/images/documents/xls.png" v-else-if="i.ext=='xlsx'"/>
                    <img src="/home/images/documents/zip.png" v-else-if="i.ext=='zip'"/>
                    <img src="/home/images/documents/pic.png" v-else-if="i.ext=='jpg' || i.ext=='png' || i.ext=='jpeg' || i.ext == 'gif'"/>
                    <img src="/home/images/documents/video.png" v-else-if="i.ext=='mp4' || i.ext=='avi'"/>
                    <p>{{i.name}}</p>
                    <a :href="i.path">下载</a>
                </div>
            </div>
        </div>
        <div class="opinion" v-if="detail.operate_status > 0">
            <div class="flex1">备注：</div>
            <div class="opinion-content">{{detail.operate_remark || '无'}}</div>
        </div>
    </div>

    <div class="foot" v-if="detail.operate_status == 0">
        <div class="send reject" @click="reject">驳回</div>
        <div class="send pass" @click="pass">同意</div>
    </div>
    <div class="foot" v-if="detail.operate_status > 0">
        <div class="send done">{{detail.operate_status_text}}</div>
    </div>
<!--    <mt-popup  position="center"  v-model="popupVisible" class="remark-popup">-->
<!--        <p>{{remark.permission < 3?remark.permission == 1?'一级分发':'二级分发':'三级实施'}}</p>-->
<!--        <div class="content">-->
<!--            <span>{{remark.username}}</span>-->
<!--            <span v-if="remark.permission < 3 && remark.status == 0" class="none">待分发</span>-->
<!--            <span v-else-if="remark.permission < 3 && remark.status == 1">已分发</span>-->
<!--            <span v-else-if="remark.permission == 3 && remark.status == 1" class="none">轮阅中</span>-->
<!--            <span v-else-if="remark.status == 2">已归档</span>-->
<!--        </div>-->
<!--        <div class="remarks">{{remark.remarks}}</div>-->
<!--    </mt-popup>-->
</div>
{/block}

{block name="script"}
<script>
    console.log({$detail});
    console.log({$approval_permission});
    var vw = new Vue({
        el: "#app",
        data: {
            detail: {$detail},
            permission: {$approval_permission},
            popupVisible: false,
            remark:{},
        },
        created() {
            this.pushHistory();
        },
        methods: {
            pushHistory() {
                window.addEventListener("popstate", function (e) {
                    self.location.reload();
                }, false);
                var state = {
                    title: "",
                    url: "#"
                };
                window.history.replaceState(state, "", "#");
            },
            pass() {
                window.location.href = "/home/documents/opinion_distribute/id/"+this.detail.id+'.html'
            },
            downFile(url) {
                window.location.href = 'http://ow365.cn/?i=19298&ssl=1&furl=https://' + window.location.host + url;
            },
            reject() {
                var _this = this;
                _this.$messagebox.prompt('填写驳回原因').then(function (response) {
                    // if(!res.value) {
                    //     _this.$toast({
                    //         message: "请输入驳回原因！",
                    //         duration: 1500
                    //     });
                    //     return false
                    // }
                    _this.$indicator.open({
                        text: '正在提交中',
                        spinnerType: 'triple-bounce'
                    });
                    _this.$http.post('{:Url("Documents/opinion_detail")}', {
                        'id': _this.detail.id,
                        'operate_status': 2,
                        'operate_remark': response.value
                    }, {emulateJSON: true}).then(function (res) {
                        console.log(res.data)
                        var data = res.data;
                        if (data.code == 1) {
                            _this.$indicator.close();
                            _this.$toast({
                                message: "驳回成功",
                                duration: 1500
                            });
                            _this.detail.operate_status = 2;
                            _this.detail.operate_status_text = '已驳回';
                            _this.detail.operate_remark = response.value;
                        } else {
                            _this.$indicator.close();
                            _this.$toast({
                                message: "驳回失败，请重试！",
                                duration: 1500
                            });
                        }
                    }, function (res) {
                        _this.$indicator.close();
                        _this.$toast({
                            message: "驳回失败，请重试！",
                            duration: 1500
                        });
                    });
                });
            },
            checkRemark(item) {
                var _this = this;
                this.remark= item;
                _this.popupVisible = true;
            }
        }
    })
</script>
{/block}
